package com.mac.demo.service.impl;

import com.mac.demo.mapper.userMapper;
import com.mac.demo.service.IUserInfo;
import com.mac.demo.vo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserIfoImpl implements IUserInfo {
    private final Logger log =  LoggerFactory.getLogger(this.getClass());

    @Autowired
    private userMapper userMapper;

    @Override
    public List<User> queryInfo(User vo) {
        log.info("查询数据：" + vo.getName());
        List<User> list = null;
        try {
            list = userMapper.queryInfo(vo);
        } catch (Exception e) {
            log.error("查询错误！");
            return null;
        }
        log.info("成功查询 " + list.size() + " 条数据！");
        return userMapper.queryInfo(vo);
    }

    public static void main(String[] args) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        //加密"0"
        String encode = bCryptPasswordEncoder.encode("123456");
        System.out.println(encode);
        //结果：$2a$10$/eEV4X7hXPzYGzOLXfCizu6h7iRisp7I116wPA3P9uRcHAKJyY4TK
    }


    @Override
    public void insertInfo(User vo) {
        userMapper.insertInfo(vo);
    }
}
